#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

string Sum(string a,string b)
{
    if(a.length()<b.length())
    {
        string temp=a; a=b; b=temp;
    }
    int i,j;
    for(i=a.length()-1,j=b.length()-1;i>=0;i--,j--)
    {
        a[i]=(a[i]+(j>=0?b[j]-'0':0));
        if(a[i]>'9')
        {
            a[i] -=10;
            if(i) a[i-1]++;
            else a='1'+a;
        }
    }
    return a;
}
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    string a[501];
    a[1]="1"; a[2]="2"; a[3]="4";
    //cout<<a[1]<<endl<<a[2]<<endl<<a[3]<<endl;
    int n,i;

    while(cin>>n && n)
    {
    for(i=4;i<=n;i++)
    {
        a[i]=Sum(a[i-1],a[i-2]);
        a[i]=Sum(a[i],a[i-3]);
    }
    cout<<a[n]<<endl;
    }

    return 0;
}
